package com.hsmpay.mobile.action.added.anj;

import it.sauronsoftware.base64.Base64;

import java.net.URLEncoder;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

import javax.annotation.Resource;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.hsmpay.qian4.pojo.PurchaseResult;
import com.hsmpay.utils.DesUtil;
import com.hsmpay.utils.TimeUtils;

import com.hsmpay.common.pojo.qian4.Qian4SendLog;
import com.hsmpay.common.pojo.user.User;
import com.hsmpay.common.util.DateConvertUtil;
import com.hsmpay.common.util.URLDecoderTools;
import com.hsmpay.mobile.action.account.qian48.Q4BaseAction;
import com.hsmpay.mobile.action.added.AddedBaseAction;
import com.hsmpay.mobile.pojo.added.AddedOrder;
import com.hsmpay.mobile.pojo.terminal.TerminalPrivileges;
import com.hsmpay.mobile.service.added.AddedOrderService;
import com.hsmpay.mobile.util.RegularUtils;

/**
 * 安纳杰
 * @author 廉月程
 */
@Controller("anNaJieAction")
@Scope("prototype")
public class AnNaJieAction extends AddedBaseAction{
	private static final long serialVersionUID = 4993789191884573156L;
	private static Logger log = Logger.getLogger(AnNaJieAction.class);
	
	@Resource(name="addedOrderService")
	private AddedOrderService<AddedOrder,Long> addedOrderService;//增值业务服务类
	
	private String cat_id;//类别ID
	private String goods_id;//商品ID
	private Integer record_number;//返回条数 默认是 10
	private Integer page_number;//页数，默认为0
	private String consignee;
	private String address;
	private String email;
	private String tel;
	private String mobile;
	private String touristsId;
	private Anj_bj add_anj = new Anj_bj();
	/**
	 * 获取商品分类
	 * @return
	 * @throws Exception
	 */
	public String getCategory()throws Exception{
		if(StringUtils.isNotEmpty(getJsonString("userId")))
			userId = Long.parseLong(getJsonString("userId"));
		if(StringUtils.isNotEmpty(getJsonString("record_number")))
			record_number = Integer.parseInt(getJsonString("record_number"));
		if(StringUtils.isNotEmpty(getJsonString("page_number")))
			page_number = Integer.parseInt(getJsonString("page_number"));
		
		if(null == userId){
			log.info("获取商品分类时, 传入参数userId为空");
			sendAppErrorMsg("6001", "userId");
			return null;
		}
		if(null == record_number){
			log.info("获取商品分类时, 传入参数record_number为空");
			sendAppErrorMsg("6001", "record_number");
			return null;
		}
		if(null == page_number){
			log.info("获取商品分类时, 传入参数page_number为空");
			sendAppErrorMsg("6001", "page_number");
			return null;
		}
		try{
			User user = userService.getUserById(userId);
			if(null != user){
				String rs = add_anj.get_category(record_number.toString(), page_number.toString());
				JSONObject json = JSONObject.fromObject(rs);
				
				JSONArray anjJson = null;
				Map<String,Object> param = new LinkedHashMap<String,Object>();
				if("true".equals(json.getString("result"))){
					param.put("reqCode", "0000");
					param.put("reqMsg", "获取商品分类成功！");
					param.put("next", json.getString("next"));
					
					String anjData = json.getString("data").toString();
					
					anjJson = JSONArray.fromObject(anjData);
					param.put("catList", anjJson);
				}else{
					param.put("reqCode", "0001");
					param.put("reqMsg", "获取商品分类失败！");
				}
				sendAppMsg(param);
			}else{
				log.warn("获取商品分类时, 用户Id="+userId+" 对应的用户不存在!");
				sendAppErrorMsg("6012", userId+"");
			}
		}catch(Exception e){
			e.printStackTrace();
			throw e;
		}
		return null;
	}
	
	/**
	 * 获取分类下的商品列表
	 * @return
	 * @throws Exception
	 */
	public String getGoods()throws Exception{
		if(StringUtils.isNotEmpty(getJsonString("userId")))
			userId = Long.parseLong(getJsonString("userId"));
		if(StringUtils.isNotEmpty(getJsonString("record_number")))
			record_number = Integer.parseInt(getJsonString("record_number"));
		if(StringUtils.isNotEmpty(getJsonString("page_number")))
			page_number = Integer.parseInt(getJsonString("page_number"));
		cat_id = getJsonString("cat_id");
		
		
		if(null == userId){
			log.info("获取分类下的商品列表时, 传入参数userId为空");
			sendAppErrorMsg("6001", "userId");
			return null;
		}
		if(null == record_number){
			log.info("获取商品分类时, 传入参数record_number为空");
			sendAppErrorMsg("6001", "record_number");
			return null;
		}
		if(null == page_number){
			log.info("获取商品分类时, 传入参数page_number为空");
			sendAppErrorMsg("6001", "page_number");
			return null;
		}
		if(StringUtils.isEmpty(cat_id)){
			log.info("获取分类下的商品列表时, 传入参数userId为空");
			sendAppErrorMsg("6001", "cat_id");
			return null;
		}

		try{
			User user = userService.getUserById(userId);
			if(null != user){
				String rs =  add_anj.get_goods(cat_id, record_number.toString(), page_number.toString());

				JSONObject json = JSONObject.fromObject(rs);
				
				JSONArray anjJson = null;
				Map<String,Object> param = new LinkedHashMap<String,Object>();
				if("true".equals(json.getString("result"))){
					param.put("reqCode", "0000");
					param.put("reqMsg", "获取商品分类成功！");
					param.put("next", json.getString("next"));
					
					String anjData = json.getString("data").toString();
					anjJson = JSONArray.fromObject(anjData);
					param.put("goods_list", anjJson);
				}else{
					param.put("reqCode", "0001");
					param.put("reqMsg", "获取商品分类失败！");
				}
				sendAppMsg(param);
			}else{
				log.warn("获取商品分类时, 用户Id="+userId+" 对应的用户不存在!");
				sendAppErrorMsg("6012", userId+"");
			}
		}catch(Exception e){
			e.printStackTrace();
			throw e;
		}
		return null;
	}
	
	/**
	 * 1.7.5.3、获取单个产品的信息
	 * @return
	 * @throws Exception
	 */
	@Deprecated
	public String getGoodsInfo()throws Exception{
		if(StringUtils.isNotEmpty(getJsonString("userId")))
			userId = Long.parseLong(getJsonString("userId"));
		goods_id = getJsonString("goods_id");
		
		
		if(null == userId){
			log.info("获取分类下的商品列表时, 传入参数userId为空");
			sendAppErrorMsg("6001", "userId");
			return null;
		}
		if(StringUtils.isEmpty(goods_id)){
			log.info("获取分类下的商品列表时, 传入参数goods_id为空");
			sendAppErrorMsg("6001", "goods_id");
			return null;
		}

		try{
			User user = userService.getUserById(userId);
			if(null != user){
				String rs = "{\"result\":\"true\",\"data\":{\"goods_id\":\"33\",\"goods_name\":\"\\u732a\\u7528\\u590d\\u5408\\u9884\\u6df7\\u6599\",\"goods_number\":\"1000\",\"shop_price\":\"1000.00\",\"goods_brief\":\"\\u732a\\u7528\\u590d\\u5408\\u9884\\u6df7\\u6599\\uff0c\\u9002\\u5408\\u5c0f\\u732a\",\"goods_thumb\":\"http:\\/\\/www.anj-bj.com\\/images\\/201503\\/thumb_img\\/33_thumb_G_1426460670488.jpg\",\"goods_img\":\"http:\\/\\/www.anj-bj.com\\/images\\/201503\\/goods_img\\/33_G_1426460670118.jpg\",\"last_update\":\"1427741561\"}}";
				JSONObject json = JSONObject.fromObject(rs);
				
				JSONObject anjJson = null;
				Map<String,Object> param = new LinkedHashMap<String,Object>();
				if("true".equals(json.getString("result"))){
					param.put("reqCode", "0000");
					param.put("reqMsg", "获取商品分类成功！");
					
					String anjData = json.getString("data").toString();
					anjJson = JSONObject.fromObject(anjData);
					param.put("goods_id", anjJson.getString("goods_id"));//goods_id：商品id
					param.put("goods_name", anjJson.getString("goods_name"));//goods_name：商品名称
					param.put("goods_number", anjJson.getString("goods_number"));//goods_number：商品库存数量
					param.put("shop_price", anjJson.getString("shop_price"));//shop_price：商品售价
					param.put("goods_brief", anjJson.getString("goods_brief"));//goods_brief：商品简介
					param.put("goods_thumb", anjJson.getString("goods_thumb"));//goods_thumb：商品缩略图
					param.put("goods_img", anjJson.getString("goods_img"));//goods_img：商品大图
					param.put("last_update", anjJson.getString("last_update"));//last_update：最后更新时间
				}else{
					param.put("reqCode", "0001");
					param.put("reqMsg", "获取商品分类失败！");
				}
				sendAppMsg(param);
			}else{
				log.warn("获取商品分类时, 用户Id="+userId+" 对应的用户不存在!");
				sendAppErrorMsg("6012", userId+"");
			}
		}catch(Exception e){
			e.printStackTrace();
			throw e;
		}
		return null;
	}
	
	/**
	 * 1.7.5.4、添加商品到购物车
	 * @return
	 * @throws Exception
	 */
	public String addCart()throws Exception{
		if(StringUtils.isNotEmpty(getJsonString("userId")))
			userId = Long.parseLong(getJsonString("userId"));
		String cartListStr = getJsonString("cartList");
		String touristsId = getJsonString("touristsId");
		
		if(null == userId){
			log.info("添加商品到购物车时, 传入参数userId为空");
			sendAppErrorMsg("6001", "userId");
			return null;
		}
		if(StringUtils.isEmpty(cartListStr)){
			log.info("添加商品到购物车时, 传入参数cartList为空");
			sendAppErrorMsg("6001", "cartList");
			return null;
		}
		if(StringUtils.isEmpty(touristsId)){
			log.info("添加商品到购物车时, 传入参数touristsId为空");
			sendAppErrorMsg("6001", "touristsId");
			return null;
		}
		
		try{
			JSONArray cartListArray = JSONArray.fromObject(cartListStr);
			if(cartListArray.size() < 1){
				log.info("添加商品到购物车时, 传入参数cartList为空");
				sendAppErrorMsg("6001", "cartList");
				return null;
			}
			
			
			User user = userService.getUserById(userId);
			if(null != user){
				String[] cartParamArray = new String[cartListArray.size()];
				for(int i=0;i<cartListArray.size();i++){
					JSONObject cart = cartListArray.getJSONObject(i);
					String goods_id_1 = cart.getString("goods_id");
					String goods_number_1 = cart.getString("goods_number");
					if(StringUtils.isEmpty(goods_id_1) || StringUtils.isEmpty(goods_number_1)){
						log.info("添加商品到购物车时, 传入参数cartList为空");
						sendAppErrorMsg("6001", "cartList");
						return null;
					}
					cartParamArray[i] = goods_id_1+"="+goods_number_1;
				}
				//JSONObject cartListJson = JSONObject.fromObject();
				
				String rs = add_anj.add_cart(touristsId, cartParamArray);
				JSONObject json = JSONObject.fromObject(rs);
				
				JSONObject anjJson = null;
				Map<String,Object> param = new LinkedHashMap<String,Object>();
				if("true".equals(json.getString("result"))){
					param.put("reqCode", "0000");
					param.put("reqMsg", "添加商品到购物车成功！");
					
					String anjData = json.getString("data").toString();
					anjJson = JSONObject.fromObject(anjData);
					//## 遍历 rs  和 cartListStr  在cartListStr 添加 isAddSucc 值
					
					for(int i=0;i<cartListArray.size();i++){
						JSONObject cart = cartListArray.getJSONObject(i);
						String goods_id_1 = cart.getString("goods_id");
						
						String isAddSucc = anjJson.getString(goods_id_1);
						if("true".equals(isAddSucc))
							cart.put("isAddSucc", true);
						else
							cart.put("isAddSucc", false);
					}
					param.put("goods_list",cartListArray);
				}else{
					param.put("reqCode", "0001");
					param.put("reqMsg", "添加商品到购物车失败！");
				}
				sendAppMsg(param);
			}else{
				log.warn("添加商品到购物车时, 用户Id="+userId+" 对应的用户不存在!");
				sendAppErrorMsg("6012", userId+"");
			}
		}catch(Exception e){
			e.printStackTrace();
			throw e;
		}
		return null;
	}
	
	/**
	 * 1.7.5.5、获取当前购物车中信息
	 * @return
	 * @throws Exception
	 */
	public String getCartGoods()throws Exception{
		if(StringUtils.isNotEmpty(getJsonString("userId")))
			userId = Long.parseLong(getJsonString("userId"));
		String touristsId = getJsonString("touristsId");
		
		if(null == userId){
			log.info("获取当前购物车中信息时, 传入参数userId为空");
			sendAppErrorMsg("6001", "userId");
			return null;
		}
		if(StringUtils.isEmpty(touristsId)){
			log.info("获取当前购物车中信息时, 传入参数touristsId为空");
			sendAppErrorMsg("6001", "touristsId");
			return null;
		}
		
		try{
			User user = userService.getUserById(userId);
			if(null != user){
				String rs = add_anj.get_cart_goods(touristsId);
				JSONObject json = JSONObject.fromObject(rs);
				
				JSONObject anjJson = null;
				Map<String,Object> param = new LinkedHashMap<String,Object>();
				if("true".equals(json.getString("result"))){
					param.put("reqCode", "0000");
					param.put("reqMsg", "获取当前购物车中信息成功！");
					
					String anjData = json.getString("data").toString();
					anjJson = JSONObject.fromObject(anjData);
					
					String goods_listStr = anjJson.getString("goods_list");
					JSONArray  goodsListArray = JSONArray.fromObject(goods_listStr);
					String totalStr = anjJson.getString("total");
					JSONObject totalJson = JSONObject.fromObject(totalStr);
					
					param.put("goods_list", goodsListArray);
					param.put("total", totalJson);
				}else{
					param.put("reqCode", "0001");
					param.put("reqMsg", "获取当前购物车中信息失败！");
				}
				sendAppMsg(param);
			}else{
				log.warn("获取当前购物车中信息时, 用户Id="+userId+" 对应的用户不存在!");
				sendAppErrorMsg("6012", userId+"");
			}
		}catch(Exception e){
			e.printStackTrace();
			throw e;
		}
		return null;
	}
	
	/**
	 * 1.7.5.6、生成订单
	 * @return
	 * @throws Exception
	 */
	public String addOrder()throws Exception{
		if(StringUtils.isNotEmpty(getJsonString("userId")))
			userId = Long.parseLong(getJsonString("userId"));
		goods_id = getJsonString("goods_id");
		consignee = getJsonString("consignee");
		address = getJsonString("address");
		email = getJsonString("email");
		tel = getJsonString("tel");
		mobile = getJsonString("mobile");
		touristsId = getJsonString("touristsId");
		
		String goods_list = getJsonString("goods_list");
		String total = getJsonString("total");
		roleId = Long.parseLong(getJsonString("roleId"));
		clientType = Integer.parseInt(getJsonString("clientType"));
		
		if(null == userId){
			log.info("生成订单时, 传入参数userId为空");
			sendAppErrorMsg("6001", "userId");
			return null;
		}
		if(StringUtils.isEmpty(touristsId)){
			log.info("生成订单时, 传入参数touristsId为空");
			sendAppErrorMsg("6001", "touristsId");
			return null;
		}
		if(StringUtils.isNotEmpty(goods_id)){
			log.info("生成订单时, 传入参数goods_id为空");
			sendAppErrorMsg("6001", "goods_id");
			return null;
		}
		if(StringUtils.isEmpty(consignee)){
			log.info("生成订单时, 传入参数consignee为空");
			sendAppErrorMsg("6001", "consignee");
			return null;
		}
		if(StringUtils.isEmpty(address)){
			log.info("生成订单时, 传入参数address为空");
			sendAppErrorMsg("6001", "address");
			return null;
		}
		if(StringUtils.isEmpty(email)){
			log.info("生成订单时, 传入参数email为空");
			sendAppErrorMsg("6001", "email");
			return null;
		}
		if(StringUtils.isEmpty(tel)){
			log.info("生成订单时, 传入参数tel为空");
			sendAppErrorMsg("6001", "tel");
			return null;
		}
		if(StringUtils.isEmpty(mobile)){
			log.info("生成订单时, 传入参数mobile为空");
			sendAppErrorMsg("6001", "mobile");
			return null;
		}
		if(!RegularUtils.checkMobile(mobile)){
			log.info("生成订单时, 手机号格式错误！");
			sendAppErrorMsg("6102");
			return null;
		}

		try{
			Date date = new Date();
			String orderNum = getOrderNumByDate(date);
			
			User user = userService.getUserById(userId);
			if(null != user){
				String rs = add_anj.add_order(touristsId, consignee, address, email, tel, mobile);
				JSONObject json = JSONObject.fromObject(rs);
				
				Map<String,Object> param = new LinkedHashMap<String,Object>();
				if("true".equals(json.getString("result"))){
					param.put("reqCode", "0000");
					param.put("reqMsg", "生成订单成功！");
					param.put("addOrderNum", orderNum);
					param.put("anjOrderNum", json.getString("data"));
					
					JSONArray goods_list_josn = JSONArray.fromObject(goods_list);
					JSONObject totalJson = JSONObject.fromObject(total);
					Double transMoney = Double.parseDouble(totalJson.getString("goods_amount"));
					
					//添加到增值业务订单表
					AddedOrder addedOrder = new AddedOrder();
					addedOrder.setOrderNum(orderNum);
					addedOrder.setTerminalTypeId(43L);//默认是安纳杰
					addedOrder.setRoleId(roleId);
					addedOrder.setClientType(clientType);
					addedOrder.setOrderTypeId(68L);//安纳杰商城
					addedOrder.setCreateDate(date);
					addedOrder.setLongTime(date.getTime());
					addedOrder.setThirdData(goods_list_josn.toString()+totalJson.toString());
					addedOrder.setUserId(userId);
					addedOrder.setMobile(mobile);
					addedOrder.setStatus(3);//未付款
					addedOrder.setTransMoney(transMoney);
					addedOrder.setThirdOrderNum(json.getString("data"));
					addedOrderService.insertEntity(addedOrder);
				}else{
					param.put("reqCode", "0001");
					param.put("reqMsg", "生成订单失败！");
				}
				sendAppMsg(param);
			}else{
				log.warn("生成订单时, 用户Id="+userId+" 对应的用户不存在!");
				sendAppErrorMsg("6012", userId+"");
			}
		}catch(Exception e){
			e.printStackTrace();
			throw e;
		}
		return null;
	}

	/**
	 * 1.7.5.7、支付
	 * @return
	 * @throws Exception
	 */
	public String addPayed()throws Exception{
		
		String merchantOrderId = getJsonString("merchantOrderId");
		merchantOrderTime = getJsonString("merchantOrderTime");
		String addOrderNum = getJsonString("addOrderNum");
		String accountNumber = getJsonString("accountNumber");
		String pin = getJsonString("pin");
		String track2Data = getJsonString("track2Data");
		String track3Data = getJsonString("track3Data");
		String signaturePath = getJsonString("signaturePath");
		String icCardYu = getJsonString("icCardYu");
		String transTerminalId = getJsonString("transTerminalId");
		
		try {
			//查询增值业务订单
			AddedOrder addedOrder = new AddedOrder();
			addedOrder.setOrderNum(addOrderNum);
			addedOrder = addedOrderService.searchEntity(addedOrder);
			Map<String,Object> param = new LinkedHashMap<String,Object>();
			String dynamicKeyData= DesUtil.generate16Key();
				
			TerminalPrivileges tp = terminalPrivilegesService.searchPrivilegesByFunctionKey("ANNAJIEMALL");
			Long payTchannel = tp.getPayTchannel();
			Long tchannelId = tp.getTchannel();
					
			Qian4SendLog send = new Qian4SendLog();
			send.setCallType(0);
			send.setUserId(userId);
			send.setOrderTypeId(68L);//安纳杰商城
			send.setApplication("Purchase.Req");
			send.setTransType("100000");//
			send.setSendTime(new Date());
			send.setSendSeqId(TimeUtils.getTimeToString());
			send.setMerchantId("137458000000001");//商户代码 ##
			send.setTerminalId("60001");
			send.setPlatformId("1");
			
			send.setMerchantOrderId(merchantOrderId);//商户订单号
			send.setMerchantOrderTime(DateConvertUtil.stringDate(merchantOrderTime,"yyyyMMddHHmmss"));//商户订单号时间
			send.setTransTime(send.getSendTime());
			send.setTransAmt(new Double(addedOrder.getTransMoney()*100).longValue()+"");
			send.setCurrency("156");
			send.setAccountNumber(accountNumber);
			send.setPin(pin);
			send.setTrack2Data(track2Data);
			send.setTrack3Data(track3Data);
			//send.setCardholderSign(cardholderSign);//电子签名
			send.setDynamicKeyData(dynamicKeyData);
//				send.setMac(mac);
			send.setCollectionType(payTchannel.intValue());
			send.setIp(URLDecoderTools.getRemoteHost(getRequest()));//IP
			send.setIcCardYu(icCardYu);
			send.setCardTypeN(StringUtils.isEmpty(icCardYu) ? 1 : 2);//1 磁条卡 2 IC卡
			send.setTransTerminalId(transTerminalId);
			
			addedOrder.setBankCard(accountNumber);
			addedOrder.setLongTime(new Date().getTime());
			addedOrder.setSignaturePath(signaturePath);
			addedOrder.setChannelId(tchannelId.longValue());
			addedOrder.setPayTchannel(payTchannel);
			addedOrder.setCardTypeN(send.getCardTypeN());//1 磁条卡 2 IC卡
			addedOrder.setTransTerminalId(transTerminalId);
			
			//去支付
			PurchaseResult prs = payOrder(send,addedOrder);
			if(0 == prs.getStatus()){//
				log.debug("支付失败");
				
				param.put("reqCode", prs.getReqCode());
				param.put("reqMsg", prs.getReqMsg());
				//修改订单
				addedOrderService.receivablesError(addedOrder.getId(),0, prs.getReqCode(), prs.getReqMsg());
				qian4SendLogService.updateResCodeMassage(send.getId(), prs.getReqCode(), prs.getReqMsg());
			}else{
				addedOrder = addedOrderService.purchaseResolveResult(addedOrder,send,prs);
				qian4SendLogService.updateResCodeMassage(send.getId(), addedOrder.getReqCode(), addedOrder.getReqMsg());
				
				if("0000".equals(addedOrder.getReqCode())){
					//String ret_url = recharge_ret_url + "?sporder_id="+orderNum+"&cardnum="+price+"&cardid=140101";
					
					//调用安纳杰支付接口
					String rs = add_anj.payed(addedOrder.getThirdOrderNum(), addedOrder.getTransMoney()+"");
					JSONObject json = JSONObject.fromObject(rs);
					
					log.debug("充值结果："+rs);
					if("true".equals(json.getString("result"))){
						//交易成功！
						addedOrderService.updateThirdCodeAndMsg(addedOrder.getId(), 1, json.getString("result"), json.getString("data"), null);
						
						param.put("reqCode", "0000");
						param.put("reqMsg", "购买成功！");
						//小票
						param.put("category", orderType.get(addedOrder.getOrderTypeId()));
						param.put("status", addedOrder.getStatus());
						param.put("orderNum", addedOrder.getOrderNum());
						param.put("transTime",  DateConvertUtil.dateString(addedOrder.getCreateDate(),"HH:mm:ss"));
						String cParam = terminalTypeId+"_"+addedOrder.getId();
						String cParamB64 = new String(Base64.encode(cParam.getBytes("UTF-8")),"UTF-8");
						param.put("certificateUrl",Certificate+URLEncoder.encode(cParamB64,"UTF-8"));
						param.put("merchantName", Q4BaseAction.MERCHANT_NAME);//商户名称
						param.put("merchantId", Q4BaseAction.MERCHANT_ID);//商户编号
						param.put("terminalId", send.getTerminalId());//终端编号
						User user = new User();
						user.setId(addedOrder.getUserId());
						user = userService.searchEntity(user);
						String acquirersName = user.getOpeningBank();
						if(null != acquirersName){
							acquirersName = acquirersName.replace("中国", "");
						}
						param.put("acquirersName", null != acquirersName ? acquirersName : addedOrder.getIssueBank());//收单行
						param.put("issueBank", null == addedOrder.getIssueBank() ? "" : addedOrder.getIssueBank());//发卡行
						param.put("bankCard", addedOrder.getBankCard());//收款卡号
						param.put("cardType", null == addedOrder.getCardType()? "" : addedOrder.getCardType());//收款卡号
						param.put("expireDate", null == addedOrder.getExpireDate() ? "" : addedOrder.getExpireDate());//卡有效期（预授权时）
						param.put("batchId", null == addedOrder.getBatchId() ? "" : addedOrder.getBatchId());//批次号
						param.put("authorizationCode", null == addedOrder.getAuthorizationCode() ? "" : addedOrder.getAuthorizationCode());//授权码
						param.put("bankTransTime", DateConvertUtil.dateString(addedOrder.getCreateDate(),"yyyy/MM/dd"));//日期/时间  transPriorSettle.getBankTransTime()
						param.put("transMoney", addedOrder.getTransMoney());//交易金额
						param.put("bankRef", addedOrder.getBankRef());//参考号
						param.put("searchId", addedOrder.getSearchId());//凭证号
						param.put("transId", addedOrder.getBankOrderNum());//银联交易流水号
						
						param.put("thirdCode", null == addedOrder.getThirdCode()?"":addedOrder.getThirdCode());//第三方代码
						param.put("thirdMsg", null == addedOrder.getThirdMsg() ? "" : addedOrder.getThirdMsg());//第三方描述
						param.put("thirdOrderNum", null == addedOrder.getThirdOrderNum() ? "" : addedOrder.getThirdOrderNum());//第三方订单号
						param.put("reqCode", addedOrder.getReqCode());
						param.put("reqMsg", addedOrder.getReqMsg());
					}else{
						log.debug(json.getString("result")+"============="+json.getString("result"));
						
						//撤销订单
						revocationOrderTimeOut(send,addedOrder.getId());
						
						param.put("reqCode", "0001");
						param.put("reqMsg", json.getString("data"));
					}
				}else {
					param.put("reqCode", addedOrder.getReqCode());
					param.put("reqMsg", addedOrder.getReqMsg());
//					param.put("reqMsg", "支付失败！");
				}
			}
			
			sendAppMsg(param);
			return null;
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
	}
	
	
	/**
	 * 取消订单
	 * @return
	 * @throws Exception
	 
	public String addCancelOrder()throws Exception{
		return null;
		String rs = "{\"result\":\"true\",\"data\":\"\\u8ba2\\u53552015040343598\\u5df2\\u53d6\\u6d88\"}";
		add_anj.cancel_order(order_sn)
	}
	*/
	
	public static void main(String args[]){
		String cartListStr = "[{\"a\":0,\"b\":1},{\"a\":1,\"b\":2},{\"a\":1,\"b\":2}]";
		JSONArray cartListArray = JSONArray.fromObject(cartListStr);
		for(int i=0;i<cartListArray.size();i++){
			System.out.println((cartListArray.get(i) instanceof JSONObject)+"     "+cartListArray.get(i));
		}
		
	}
}
